package procsim;

import java.awt.*;

public class GAdder extends Adder implements GraphicalElement {

    private int width = 110;
    private int height = 60;
    private int x, y;

    public GAdder(int num){
        super(num);
    }

    public GAdder(int num, MSignal inSigA, MSignal inSigB){
        super(num, inSigA, inSigB);
    }

    @Override
    public void setCoords(int x, int y){
        this.x = x;
        this.y = y;
    }

    @Override
    public int getWidth() {
        return width;
    }

    @Override
    public int getHeight() {
        return height;
    }

    @Override
    public void setSize(int width, int height) {
        this.width = width;
        this.height = height;
    }

    @Override
    public void drawIt(Graphics2D g, int x, int y) {
        Util.saveGraphics(g);
        g.setColor(Color.BLACK);
        g.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));
        g.drawRect(x+1, y+1, width-2, height-2);
        g.drawString("A", x+12, y+15);
        g.drawString("B", x+width-18, y+15);
        g.drawString("F", x+width/2-3, y+height-5);
        g.setFont(new Font(Font.MONOSPACED, Font.BOLD, 16));
        g.drawString("ADD", x+width/2-15, y+height/2+5);
        Util.restoreGraphics(g);
    }

    @Override
    public void drawIt(Graphics2D g) {
        drawIt(g, x, y);
    }

    public Coords getInACoords(int length){
        return new Coords(x+15, y-length, x+15, y);
    }

    public Coords getInBCoords(int length){
        return new Coords(x+getWidth()-15, y-length, x+getWidth()-15, y);
    }

    public Coords getResCoords(int length){
        return new Coords(x+getWidth()/2, y+getHeight()+1, x+getWidth()/2, y+getHeight()+length);
    }

}
